home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / h / PBlackBox.h < prev   
Encoding:
C/C++ Source or Header  |  1994-09-14  |  2.2 KB  |  79 lines  |  [TEXT/MPS ]

  1. #ifndef PBLACKBOX_H
  2. #define PBLACKBOX_H
  3.  
  4. /*
  5.  * SOFTWARE RIGHTS
  6.  *
  7.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  8.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  9.  * company may do whatever they wish with source code distributed with
  10.  * PCCTS or the code generated by PCCTS, including the incorporation of
  11.  * PCCTS, or its output, into commerical software.
  12.  * 
  13.  * We encourage users to develop software with PCCTS.  However, we do ask
  14.  * that credit is given to us for developing PCCTS.  By "credit",
  15.  * we mean that if you incorporate our source code into one of your
  16.  * programs (commercial product, research project, or otherwise) that you
  17.  * acknowledge this fact somewhere in the documentation, research report,
  18.  * etc...  If you like PCCTS and have developed a nice tool with the
  19.  * output, please mention that you developed it using PCCTS.  In
  20.  * addition, we ask that this header remain intact in our source code.
  21.  * As long as these guidelines are kept, we expect to continue enhancing
  22.  * this system and expect to make other tools available as they are
  23.  * completed.
  24.  *
  25.  * ANTLR 1.23
  26.  * Terence Parr
  27.  * Parr Research Corporation
  28.  * with Purdue University and AHPCRC, University of Minnesota
  29.  * 1989-1994
  30.  */
  31.  
  32. template<class Lexer, class Parser, class Token>
  33. class ParserBlackBox {
  34. protected:
  35.     DLGFileInput *in;
  36.     Lexer *scan;
  37.     Token *tok;
  38.     ANTLRTokenBuffer *pipe;
  39.     Parser *_parser;
  40.     FILE *file;
  41. public:
  42.     
  43.     ParserBlackBox(FILE *f)
  44.         {
  45.             file = f;
  46.             in = new DLGFileInput(f);
  47.             scan = new Lexer(in);
  48.             pipe = new ANTLRTokenBuffer(scan);
  49.             tok = new Token;
  50.             scan->setToken(tok);
  51.             _parser = new Parser(pipe);
  52.             _parser->init();
  53.         }
  54.     ParserBlackBox(char *fname)
  55.         {
  56.             FILE *f = fopen(fname, "r");
  57.             if ( f==NULL ) {cerr << "cannot open " << fname << "\n"; return;}
  58.             else {
  59.                 file = f;
  60.                 in = new DLGFileInput(f);
  61.                 scan = new Lexer(in);
  62.                 pipe = new ANTLRTokenBuffer(scan);
  63.                 tok = new Token;
  64.                 scan->setToken(tok);
  65.                 _parser = new Parser(pipe);
  66.                 _parser->init();
  67.             }
  68.         }
  69.     ~ParserBlackBox()
  70.         {
  71.             delete in; delete scan; delete pipe; delete _parser; delete tok;
  72.             fclose(file);
  73.         }
  74.  
  75.     Parser *parser()    { return _parser; }
  76. };
  77.  
  78. #endif
  79.